class Tree {
  constructor(public left, public value, public right) {
  }
}
//['A', 'B', 'D','E', 'C', 'F','G']
function* leftOrder(tree) {
  if (tree) {
    yield tree.value
    yield* leftOrder(tree.left)
    yield* leftOrder(tree.right)
  }
}

//['D', 'B', 'E','A', 'F', 'C','G']
function* inOrder(tree) {
  if (tree) {
    yield* inOrder(tree.left)
    yield tree.value
    yield* inOrder(tree.right)
  }
}
//['D', 'E', 'B','F', 'G', 'C','A']
function* rightOrder(tree) {
  if (tree) {
    yield* rightOrder(tree.left)
    yield* rightOrder(tree.right)
    yield tree.value
  }
}
function make(array) {
  if (array.length === 1) return new Tree(null, array[0], null)
  return new Tree(make(array[0]), array[1], make(array[2]))
}
const tree = make([[['D'], 'B', ['E']], 'A', [['F'], 'C', ['G']]])
const result: any[] = []
for (const node of rightOrder(tree)) {
  result.push(node)
}
console.log(result)
